<?php
namespace app\api\controller\user;
use think\File;
use think\facade\Env;
use app\common\model\user\User as UserModel;
use app\common\model\company\Company;
use app\common\model\orderdata\Goods;
use app\common\model\quotation\QuotationList;
use app\common\model\buss\Buss;
use app\common\model\power\Rolepowerlnk;
use app\api\controller\Base;
use app\common\model\power\Rolepower;
use app\common\model\pub\Telbind;
class Manauser extends Base
{
	/**
	 * 产生jwt加密串，参考session
	 */
    public function initialize(){
		parent::initialize();
		self::is_login();
		Rolepower::powerguard(205001);
	}

	/**
     * 获取关联员工列表
     * @return [type] [description]
     */
    public function getstafflist(){
    	$data = UserModel::get_stafflist();
    	return myok($data);
    }

	/**
     * 添加收集员
     * @return [type] [description]
     */
    public function adduser()
    {
        $data = input('post.');
        if (empty($data['Iphone'])) {
            return myerr('请输入联系方式');
        }

        if (empty($data['Name'])) {
            return myerr('请输入姓名');
        }

        if (empty($data['Role'])) {
            return myerr('请选择角色');
        }
        //判断角色是否正确
        if(getrolename($data['Role'])=='暂无角色权限'){
        	return myerr('暂无角色权限');
        }
       	//创建一个用户账号名称以司机名为准
       	$userid = UserModel::user_createuser($data['Iphone'], $data['Role'], $data['Name']);
       	if($data['Role']=='201'||$data['Role']=='204'){
       		Buss::create_user_init($userid,$data['Name'],$data['Iphone']);
       	}
	   	return myok('新增成功');
    }

    /**
     * 锁定用户
     * @return [type] [description]
     */
    public function user_lock(){
    	$id = input('id');
    	if(empty($id)){
    		return moerr('缺少重要参数');
    	}
    	$sb = UserModel::user_lock($id);
    	return myok($sb['msg']);
    }

	/**
	 * 判断账号是否登录
	 * @return boolean [description]
	 */
	private function is_login(){
		$data = UserModel::is_sessionlogin();
		if (!$data['code']) {
			$data['options'] = 'relogin';
			json($data)->send();
			exit;
		}
	}
}
